using System;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace octalforty.Syndication.uF.UI
{
	/// <summary>
	/// Provides a base class for Microformat web controls.
	/// </summary>
	public abstract class MicroformatWebControl : WebControl
	{
		#region Private Member Variables
		private Boolean hidden;
		#endregion

		#region Public Properties
		/// <summary>
		/// Gets or sets a value which indicates whether this control is visible
		/// on the page or not.
		/// </summary>
		/// <remarks>
		/// Do not confuse with <see cref="Control.Visible"/> property, which controls
		/// the rendering. The difference is that setting <see cref="Hidden"/> property
		/// to <c>true</c> renders this control with <c>display: none;</c> style.
		/// </remarks>
		public Boolean Hidden
		{
			get { return hidden; }
			set { hidden = value; }
		}
		#endregion

		/// <summary>
		/// Initializes a new instance of <see cref="MicroformatWebControl"/> class.
		/// </summary>
		protected MicroformatWebControl()
		{
		}

        /// <summary>
        /// Renders a Microformat tag <paramref name="microformatClass"/> with the <c>class</c>
        /// value of <paramref name="microformatClass"/>.
        /// </summary>
        /// <param name="htmlTextWriter"></param>
        /// <param name="microformatTag"></param>
        /// <param name="microformatClass"></param>
        /// <param name="value"></param>
        /// <remarks>
        /// The tag is rendered only if <paramref name="microformatClass"/> is not empty.
        /// </remarks>
        protected static void RenderMicroformatTag(HtmlTextWriter htmlTextWriter, 
            HtmlTextWriterTag microformatTag, String microformatClass, String value)
        {
            if(value == null || value == string.Empty)
                return;

            htmlTextWriter.AddAttribute(HtmlTextWriterAttribute.Class, microformatClass);
            htmlTextWriter.RenderBeginTag(microformatTag);

            htmlTextWriter.Write(value);

            htmlTextWriter.RenderEndTag();
        }
	}
}
